﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YasharEl.Infrastructure.Core.Prototype;
using YasharEl.Infrastructure.EntityModel;
using YasharEl.Infrastructure.ObjectFactory;

namespace YasharEl.Infrastructure.Core.EntityModel.Prototype
{
    public static class DataTypeValueConverterFactory
    {
        public static IDataTypeValueConverter CreateValueConverter(DataType dataType, IDependencyResolver resolver)
        {
            if (dataType == null)
                throw new DataTypeMissingException();

            if (dataType == DataType.String)
            {
                return new StringValueConverter();
            }
            if (dataType == DataType.Long)
            {
                return new LongValueConverter();
            }
            if (dataType == DataType.Integer)
            {
                return new IntegerValueConverter();
            }
            if (dataType == DataType.Double)
            {
                return new DoubleValueConverter();
            }
            if (dataType == DataType.Decimal)
            {
                return new DecimalValueConverter();
            }
            if (dataType == DataType.DateTime)
            {
                return new DateTimeValueConverter(resolver.Resolve<IDateTimeProvider>());
            }
            if (dataType == DataType.Boolean)
            {
                return new BooleanValueConverter();
            }
            if (dataType == DataType.Address)
            {
                return new AddressValueConverter();
            }

            throw new NotSupportedException(string.Format("DataType converter for type {0} not supported yet.", dataType.Value));
        }
    }
}
